// 封装所有请求操作
import axios from '../../index'
import qs from 'qs'


// 合同列表
export const agreementList = (page, limit) => {
    console.log(page);
    console.log(limit);
    return axios({
        url: '/Contract/queryContractMap',
        method: 'GET',
        params: {
            page, // 页数
            limit // 一页的数据总量
        }
    })
}

// 今日新增
export const todayIncrease = (page, limit) => {
    return axios({
        url: '/Contract/searchContractByStartday',
        method: 'GET',
        params: {
            page,
            limit
        }
    })
}

// 删除函数
export const agreementdel = (contract_no, value) => {
    return axios({
        url: '/Contract/deleteContractByNo',
        method: 'POST',
        data: qs.stringify({
            contract_no: contract_no,
            value: value
        })
    })
}

//编辑合同完成，返回新增数据
export const addcontranct = (obj) => {
    console.log(obj);
    return axios({
        url: '/Contract/insertNewContractList',
        method: 'POST',
        data: {
            customer_Id: obj.customer_Id,
            contract_no: obj.contract_no,
            contract_part: obj.contract_part,
            order_id: obj.order_id,
            contract_startday: obj.contract_startday,
            contract_endday: obj.contract_endday,
            contract_summoney: obj.contract_summoney,
            contract_receivemoney: obj.contract_receivemoney,
            contract_tax: obj.contract_tax,
            contract_invoice: obj.contract_invoice,
            contract_comment: obj.contract_comment,
            contract_enterday: obj.contract_enterday,
            employee_id: obj.employee_id,
            contract_debtmoney: obj.contract_debtmoney,
        }

    })
}

// 合同修改
export const changecontranct = (obj) => {
    return axios({
        url: '/Contract/updateContractList',
        method: 'POST',
        data: {
            contract_no: obj.contract_no,
            contract_id: obj.contract_id,
            order_id: obj.order_id,
            contract_startday: obj.contract_startday,
            contract_endday: obj.contract_endday,
            contract_summoney: obj.contract_summoney,
            contract_debtmoney: obj.contract_debtmoney,
            contract_receivemoney: obj.contract_receivemoney,
            contract_tax: obj.contract_tax,
            contract_invoice: obj.contract_invoice,
            contract_comment: obj.contract_comment,
            contract_enterday: obj.contract_enterday,
            employee_id: obj.employee_id,
            contract_part: obj.contract_part,
        }
    })
}

//简单搜索
export const easySearch = (val) => {
    // console.log(val);
    return axios({
        url: '/Contract/searchContractByName',
        method: 'GET',
        params: {
            contract_search: val
        }
    })
}

//合同续费
export const renew = (obj) => {
    console.log(obj.newcontract_endday);
    console.log(obj.newcontract_summoney);
    console.log(obj.newcontract_receivemoney);
    console.log(obj.contract_id);
    return axios({
        url: '/Contract/updateContractRenewList',
        method: 'POST',
        data: qs.stringify({
            contract_endday: obj.newcontract_endday,
            contract_summoney: obj.newcontract_summoney,
            contract_receivemoney: obj.newcontract_receivemoney,
            contract_id: obj.contract_id
        })
    })
}

//合同到款
export const contranctReceivePayment = (contract_receivemoney, contract_id) => {
    return axios({
        url: '/Contract/updateContractReceive',
        method: 'POST',
        data: qs.stringify({
            contract_receivemoney,
            contract_id
        })
    })
}

//合同状态
export const contranctstatus = (status, desc, time, contract_id, employee_id) => {
    return axios({
        url: '/Contract/updateContractStatusList',
        method: 'POST',
        data: {
            contract_status_no: status,
            contract_status_comment: desc,
            employee_id: employee_id,
            contract_startday: time,
            contract_id: contract_id
        }
    })
}

// 本周新增
export const weekIncrease = (page, limit) => {
    return axios({
        url: '/Contract/searchDueContractByWeek',
        method: 'GET',
        params: {
            page,
            limit
        }
    })
}

//本月新增
export const monthIncrease = (page, limit) => {
    return axios({
        url: '/Contract/searchNewContractByMonth',
        method: 'GET',
        params: {
            page,
            limit
        }
    })
}

//今日到期
export const todayDeal = (page, limit) => {
    return axios({
        url: '/Contract/searchContractByEndday',
        method: 'GET',
        params: {
            page,
            limit
        }
    })
}

//本周到期
export const weekDeal = (page, limit) => {
    return axios({
        url: '/Contract/searchDueContractByWeek',
        method: 'GET',
        params: {
            page,
            limit
        }
    })
}

//本月到期
export const monthDeal = (page, limit) => {
    return axios({
        url: '/Contract/searchDueContractByMonth',
        method: 'GET',
        params: {
            page,
            limit
        }
    })
}

//附件入库
// export const addfiles = () => {
//     return axios({
//         url: api + '/Contract/searchDueContractByMonth',
//         method: 'GET',
//         params: {
//             page,
//             limit
//         }
//     })
// }

//新增合同分类
export const addkinds = (name) => {
    console.log(name);
    return axios({
        url: '/Contract/insertContractPart',
        method: 'GET',
        params:{
            contract_newPart:name
        }
    })
}
